// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
// import Vuex from 'vuex'
import App from './App'
import router from './router'
import Mint from 'mint-ui'
import {$get, $post} from './util/common'
import 'mint-ui/lib/style.css'
import Util from './util/utils'
import wechat from 'weixin-js-sdk'

Vue.use(Mint)
// Vue.use(Vuex)

Vue.prototype.$get = $get
Vue.prototype.$post = $post

/* 微信分享 */
Vue.prototype.wechatShare = (shareData) => {
  let resource = {
    title: '交易码券，随我心愿！惠权益！',
    desc: '要想生活过得去，就得关注惠权益！体验优质服务，玩卡不再累心累力！',
    link: 'https://www.bettercard.cn/new_html/#/shareReg?flag_user=',
    img: 'https://www.bettercard.cn/views/default/skin/images/share_logo.jpg'
  }
  let obj = Object.assign({}, resource, shareData)
  let params = {url: window.location.href}
  $post('/vue/setting/get_jsapi_ticket', params).then(data => {
    // 分享标题等参数
    const shareTitle = obj.title
    const shareDesc = obj.desc
    const shareLink = obj.userShare ? obj.link + data.flag : obj.link
    const shareImgUrl = obj.img
    wechat.config({
      debug: false,
      appId: data.appid, // 和获取Ticke的必须一样------必填，公众号的唯一标识
      timestamp: data.timestamp, // 必填，生成签名的时间戳
      nonceStr: data.noncestr, // 必填，生成签名的随机串
      signature: data.signature, // 必填，签名，见附录1
      // 需要分享的列表项:发送给朋友，分享到朋友圈，分享到QQ，分享到QQ空间
      jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo', 'onMenuShareQZone', 'startRecord', 'stopRecord', 'onVoiceRecordEnd', 'playVoice', 'pauseVoice', 'stopVoice', 'onVoicePlayEnd', 'uploadVoice', 'downloadVoice', 'chooseImage', 'previewImage', 'uploadImage', 'downloadImage', 'translateVoice', 'getNetworkType', 'openLocation', 'getLocation', 'hideOptionMenu', 'showOptionMenu', 'hideMenuItems', 'showMenuItems', 'hideAllNonBaseMenuItem', 'showAllNonBaseMenuItem', 'closeWindow', 'scanQRCode', 'chooseWXPay', 'openProductSpecificView', 'addCard', 'chooseCard', 'openCard']
    })
    // 处理验证失败的信息
    wechat.error(function (res) {
      console.log('验证失败返回的信息:', res)
    })
    // 处理验证成功的信息
    wechat.ready(function () {
      // 分享给朋友
      wechat.onMenuShareAppMessage({
        title: shareTitle, // 分享标题
        desc: shareDesc, // 分享描述
        link: shareLink, // 分享链接
        imgUrl: shareImgUrl, // 分享图标
        type: '', // 分享类型,music、video或link，不填默认为link
        dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
        success: function () {},
        cancel: function () {}
      })
      // 分享到朋友圈
      wechat.onMenuShareTimeline({
        title: shareTitle,
        link: shareLink,
        imgUrl: shareImgUrl,
        success: function () {},
        cancel: function () {}
      })
      // 分享到qq
      wechat.onMenuShareQZone({
        title: shareTitle,
        desc: shareDesc,
        link: shareLink,
        imgUrl: shareImgUrl,
        success: function () {},
        cancel: function () {}
      })
      // 分享到微博
      wechat.onMenuShareWeibo({
        title: shareTitle,
        desc: shareDesc,
        link: shareLink,
        imgUrl: shareImgUrl,
        success: function () {},
        cancel: function () {}
      })
      // 分享到qq空间
      wechat.onMenuShareQZone({
        title: shareTitle,
        desc: shareDesc,
        link: shareLink,
        imgUrl: shareImgUrl,
        success: function () {},
        cancel: function () {}
      })
    })
  })
}

Vue.config.productionTip = false

router.beforeEach((to, from, next) => {
  /* 动态修改页面标题 */
  Util.title(to.meta.title)
  next()
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  template: '<App/>',
  components: { App }
})
